From natural semantics to C: A formal derivation of two STG machines
نویسندگان
چکیده
The Spineless Tag-less G-machine (STG machine) was defined as the target abstract machine for compiling the lazy functional language Haskell. It is at the heart of the Glasgow Haskell Compiler (GHC) which is claimed to be the Haskell compiler that generates the most efficient code. A high-level description of the STG machine can be found at (Peyton Jones, 1992; Marlow & Peyton Jones, 2004; Marlow & Peyton Jones, 2006). Should the reader be interested in a more detailed view, then the only additional information available is the Haskell code of GHC and the C code of its runtime system. It is hard to prove that this machine correctly implements the lazy semantics of Haskell. Part of the problem lies in the fact that the STG machine executes a bare-bones functional language, called STGL, much lower level than Haskell. Therefore, part of the correctness should be —and it is— established by showing that the translation from Haskell to STGL preserves Haskell’s semantics. The other part involves showing that the STG machine correctly implements the lazy semantics of STGL. In this paper we provide a step-by-step formal derivation of the STG machine and of its compilation to C, starting from a natural semantics of STGL. Thus, our starting point is higher level than the descriptions found at (Peyton Jones, 1992) and (Marlow & Peyton Jones, 2004), and our arrival point is lower level than those works. Additionally, there has been substantial changes between the so-called push/enter model of the STG machine described in (Peyton Jones, 1992), and the eval/apply model of the STG machine described in (Marlow & Peyton Jones, 2004). So, in fact, we derive two machines instead of one, starting from the same initial semantics. At each step we provide enough intuitions and explanations in order to understand the refinement, and then the formal definitions and statements proving that the derivation step is sound and complete. The main contribution of the paper is to show that an efficient machine such as the STG can be presented, understood, and formally reasoned about at different levels of abstraction.
منابع مشابه
A short introduction to two approaches in formal verification of security protocols: model checking and theorem proving
In this paper, we shortly review two formal approaches in verification of security protocols; model checking and theorem proving. Model checking is based on studying the behavior of protocols via generating all different behaviors of a protocol and checking whether the desired goals are satisfied in all instances or not. We investigate Scyther operational semantics as n example of this...
متن کاملAn intensional semantics for elementary program transformations
This paper is a contribution to the formal study and analysis of vernacular forms of program derivation. Specifically, in this paper, our vernacular derivations are elementary program transformations over the natural numbers. We provide an intensional semantics for these transformations within the derivations of the Elementary theory of Operations and Numbers, EON, [Bee85]. This semantics is in...
متن کاملAn Adjunction-Theoretic Foundation for Proof Search in Intuitionistic First-Order Categorical Logic Programming
In this thesis we compose a proof-theoretic approach to logic programming with a category-theoretic approach to proof theory. This allows us to present the computation mechanisms of several systems of logic programming as proof search strategies within an intuitionistic first-order sequent calculus with logic variables and to analyze aspects of their behavior algebraically. Beginning from the b...
متن کاملUML 2.0 State Machines: Complete Formal Semantics Via core state machine
UML has become the standard modeling language for object-oriented systems. The informal description of UML and its continuous extension cause many ambiguities. Therefore, a formal semantics for UML is necessary, especially for formal reasoning and tool development. We present a formal semantics of UML 2.0 state machines, which are used for modeling the reactive behavior of objects, by (i) deriv...
متن کاملFormal approach on modeling and predicting of software system security: Stochastic petri net
To evaluate and predict component-based software security, a two-dimensional model of software security is proposed by Stochastic Petri Net in this paper. In this approach, the software security is modeled by graphical presentation ability of Petri nets, and the quantitative prediction is provided by the evaluation capability of Stochastic Petri Net and the computing power of Markov chain. Each...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
عنوان ژورنال:
- J. Funct. Program.
دوره 19 شماره
صفحات -
تاریخ انتشار 2009